<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<body class="easyui-layout">
<!-- 说明 字符串：Finance，作为替换字符串 -->
<div class="easyui-layout" style="width:100%;height:100%;">
    <!-- 主表  -->
    <table id="jijin_item_table" class="easyui-treegrid" title="" style="width:100%;height:100%;padding-bottom: 0px;"
           data-options="rownumbers:true, pagination:true,singleSelect:true,
		            url:'/jijinitem-list/1/20/'+${id},
					  method:'get',
					  toolbar:'#tb',
					  idField: 'id',
					  animate: true,
					  onDblClickRow:onDblClickRow,
                   lines:true,
                   treeField: 'itemName',
					  loadMsg : '数据加载中',
					  onLoadSuccess:function(data){
                        $('.add').linkbutton({plain:true,iconCls:'icon-add'});
                        $('.delete').linkbutton({plain:true,iconCls:'icon-remove'});
                        $('.upload').linkbutton({plain:true,iconCls:'icon-upload'});
                        $('.edit').linkbutton({plain:true,iconCls:'icon-edit'});
                          $('.uuid').linkbutton({plain:true,iconCls:'icon-new'});
                   },
					  showFooter: true" >
        <thead>
        <tr>
            <th data-options="field:'detailId',width:40,align:'center',formatter:detailIdfile"></th>
            <th data-options="field:'itemName',width:280,align:'left' ">基金名称</th>
            <th data-options="field:'itemTime',width:110,align:'center' ">基金投资时间</th>
            <th data-options="field:'itemMoney',width:110,align:'center' ">项目金额</th>
            <th data-options="field:'itemOutTime',width:110,align:'center' ">预计退出时间</th>
            <th data-options="field:'itemOutMoney',width:110,align:'center' ">预计收益(万)</th>
            <th data-options="field:'itemCondition',width:150,align:'center' ">备注</th>
            <th data-options="field:'id',width:150,align:'center' ,formatter:idFormatter ">操作</th>
        </tr>
        </thead>
    </table>
</div>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
    <div>
        模板名称1:<input class="easyui-textbox" id="to" style="width:120px" >
        <a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
    </div>
    <div style="margin:5px 0;"></div>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" id="add">新增</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-edit'" id="edit">修改</a>
    <a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-download'"  id="edit">导出</a>
</div>


<script>
    // 根据后台relation参数判断父子节点，返回不同按钮
    function idFormatter(value,row) {
        var button ='';
        button += '<a href="#" class="add" title="新增" onclick=\'add('+value+','+'-1'+')\'></a>';
        button += '<a href="#" class="delete" title="删除" onclick=\'del('+value+')\'></a>';
        if(row.relation=='son'){
            button = '';
            button = '<a href="#" class="upload" title="上传" onclick=\'upload_info('+row._parentId+','+row.detailId+')\'></a>';
            button += '<a href="#" class="edit" title="修改" onclick=\'add('+row._parentId+','+row.detailId+')\'></a>';
            button += '<a href="#" class="delete" title="删除" onclick=\'detailDel('+row._parentId+','+row.detailId+')\'></a>';
        }
        return button;
    }

</script>

<!-- 按钮操作 -->
<script type="text/javascript">

    function onDblClickRow(rowIndex,rowData){

        var id = rowIndex.id;
        var title = rowIndex.itemName;
        var url = '/jijinItem-onDbClick-view/'+id;
        if(rowIndex._parentId != null){
            layer.msg("请双击基金查看详情！",{time:2000});
            return;
        }
        var index = layer.open({
            type: 2,
            title:title,
            area: ['420px', '240px'], //宽高
            closeBtn: 1, //不显示关闭按钮
            anim: 2,
            maxmin: true,
            shadeClose: true, //开启遮罩关闭
            content: url
        });
        layer.full(index);
    }

    $('#add').click(function () {
        var id = ${id};
        var url = '/project-item-add/'+id;
        var index = parent.layer.open({
            title:'基金-新增项目',
            type: 2,
            area: ['950px', '650px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end: function(){
                $('#jijin_item_table').treegrid('reload');
            }
        });
    });
    //编辑
    $('#edit').click(function () {
        var row = $('#jijin_item_table').treegrid('getSelected');
        if (row){
            var id = row.id;
            var url = '/project-item-edit/'+id;
            var index = parent.layer.open({
                title:'基金-修改项目',
                type: 2,
                area: ['950px', '650px'],
                fixed: true, //不固定
                maxmin: true,
                content: url,
                end: function(){
                    $('#jijin_item_table').treegrid('reload');
                }
            });
        } else{
            parent.layer.msg("请选择需要修改的基金信息！")
        }
    });
    function add(itemId,detailId) {
        var id = ${id!};
        var url = '/jijin-detail-add/'+id+'/'+itemId+'/'+detailId;
        var index = parent.layer.open({
            title:'基金项目-新增描述',
            type: 2,
            area: ['950px', '650px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end: function(){
                $('#jijin_item_table').treegrid('reload',itemId);
            }
        });
    }
    function  del(val) {
        parent.layer.confirm('你确定要删除此项目信息？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/jijinitem-ins-upd-del/'+val,
                data : {tm:new Date().getTime(),deleteFlag:'Y'},
                async: false,
                type : 'post',
                success :function (result) {
                    layer.alert(result);
                    $('#jijin_item_table').treegrid('reload');
                }
            })
            parent.layer.closeAll('dialog');
        }, function(){

        });
    }

    function upload_info(jijinId,jijinDetailid) {
        var id = ${id!};
        var url = '/project-touhou-upload/'+id+'/th_jijinDetail_'+jijinDetailid;
        var index = parent.layer.open({
            title:'投后管理-基金资料上传',
            type: 2,
            area: ['700px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url,
            end: function(){
                $('#jijin_item_table').treegrid('reload',jijinId);
            }
        });
    }

    //删除detail
    function detailDel(itemId,itemDetailId) {

        parent.layer.confirm('你确定要删除此项目信息？', {
            btn: ['删除','取消'] //按钮
        }, function(){
            $.ajax({
                url : '/jijindetail-ins-upd-del/'+itemDetailId,
                data : {tm:new Date().getTime(),deleteFlag:'Y'},
                async: false,
                type : 'post',
                success :function () {
                    $('#jijin_item_table').treegrid('reload',itemId);
                }
            })
            parent.layer.closeAll('dialog');
        }, function(){
        });
        
    }
    //value ;
    function detailIdfile(value,row){
        var  projectId = ${id!};
        var result = '';
        $.ajax({
            url : '/project-touhou-has-file/'+projectId+'/th_jijinDetail_'+row.detailId,
            async : false,
            success :function (data) {
                result = data;
            }
        })
        var button = '';
        if(result){
            button += '<a href="#" class="uuid" title="文件已经上传" onclick="uidFile(\''+projectId+'\','+row.detailId+')"></a>';
        }
        return button;
    }
    function uidFile(value,id){
        var url = '/project-touhou-files-show/'+value+'/th_jijinDetail_'+id;
        var index = layer.open({
            title: false,
            type: 2,
            area: ['900px', '450px'],
            fixed: true, //不固定
            maxmin: true,
            content: url
        });
    }
</script>
<!-- 分页 -->
<script type="text/javascript">
    $(function(){
        var p = $('#jijin_item_table').treegrid('getPager');
        p.pagination({
            pageSize: 20, //每页显示的记录条数，默认为10
            pageList: [20, 40, 60], //可以设置每页记录条数的列表
            onSelectPage: function (pageNumber, pageSize) {
                if(pageNumber==0){
                    pageNumber = 1;
                }
                var handler = '/jijinitem-list/'+pageNumber+"/"+pageSize+'/'+${id};
                $('#jijin_item_table').treegrid('options').url = handler;
                $('#jijin_item_table').treegrid('reload');
            }
        });
    })
</script>